# -*- coding:utf-8 -*-
import httplib, urllib, json
 
#定义需要进行发送的数据   
#定义一些文件头   
headers = {"Content-Type":"application/x-www-form-urlencoded",   
                   "Connection":"Keep-Alive","Referer":"http://127.0.0.1/"};   
#与网站构建一个连接   
conn = httplib.HTTPConnection("127.0.0.1", 8080);   
myurl = '/discuss'
#开始进行数据提交   同时也可以使用get进行   

ding_item = {}
ding_item['type'] = 'ding_discuss'
ding_item['id'] = 1
ding_item['uid'] = 1
ding_item['code'] = '54ix6K+t56e75Yqo5byA5Y+R6ICFOjhhYWVlYWVkNDk0NmExZmQxZTBkYmY5MTNmZWUxMDI2'
#ding_item['code'] = ''
params = urllib.urlencode(ding_item); 
conn.request(method="POST", url=myurl, body=params, headers=headers);
#返回处理后的数据   
response = conn.getresponse(); 
#判断是否提交成功   
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

ding_item = {}
ding_item['type'] = 'ding_cmt'
ding_item['id']  = 1
ding_item['title']  = 'xxoo is so good'
ding_item['cmt_id']  = 1
ding_item['cmt_uid'] = 1
ding_item['cmt'] = '撸出个未来'
ding_item['code'] = '54ix6K+t56e75Yqo5byA5Y+R6ICFOjhhYWVlYWVkNDk0NmExZmQxZTBkYmY5MTNmZWUxMDI2'
params = urllib.urlencode(ding_item); 
conn.request(method="POST", url=myurl, body=params, headers=headers);
#返回处理后的数据   
response = conn.getresponse(); 
#判断是否提交成功   
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

cmt_item = {}
cmt_item['reply'] = '撸出个未来abc'
cmt_item['cmt'] = '金刚葫芦娃'
cmt_item['cmt_uid'] = 11
cmt_item['cmt_uname'] = '小水牛'
cmt_item['phone_type'] = 'HTC Incredible S'
cmt_item['code'] = '54ix6K+t56e75Yqo5byA5Y+R6ICFOjhhYWVlYWVkNDk0NmExZmQxZTBkYmY5MTNmZWUxMDI2'
cmt_item['id'] = 1
cmt_item['uid'] = 1
cmt_item['type'] = 'post_cmt'
params = urllib.urlencode(cmt_item); 
conn.request(method="POST", url=myurl, body=params, headers=headers);
#返回处理后的数据   
response = conn.getresponse(); 
#判断是否提交成功   
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

discuss_item = {}
discuss_item['title'] = 'wocaoaaa,我老婆不和我嘿咻，怎么办?'
discuss_item['content'] = '愁死我了'
discuss_item['type'] = 'post_discuss'
discuss_item['code'] = '54ix6K+t56e75Yqo5byA5Y+R6ICFOjhhYWVlYWVkNDk0NmExZmQxZTBkYmY5MTNmZWUxMDI2'
params = urllib.urlencode(discuss_item); 
conn.request(method="POST", url=myurl, body=params, headers=headers);
#返回处理后的数据   
response = conn.getresponse(); 
#判断是否提交成功   
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

conn.close();
